/***************************************************************************
 *                         CHM hhc file parser                             *
 *                           -------------------                           *
 *                                                                         *
 *  author:     Nestle <zhurx4g@gmail.com>                                 *
 *  notes:                                                                 *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Lesser General Public License as        *
 *   published by the Free Software Foundation; either version 2.1 of the  *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#ifndef QCHM_H
#define QCHM_H

#if defined(QTCHM_LIBRARY)
#  define QTCHMSHARED_EXPORT Q_DECL_EXPORT
#else
#  define QTCHMSHARED_EXPORT Q_DECL_IMPORT
#endif

#include <QString>
#include <QMap>
#include <QDir>
#include <QStringList>
#include <QByteArray>
#include "qdefaulthhchandler.h"



class QTCHMSHARED_EXPORT ChmEntityInfo
{
public:
    long         start;
    long         length;
    int          space;
    int          flags;
    char         path[512+1];
};

class QTCHMSHARED_EXPORT QChm : public QObject{
    Q_OBJECT
public:
    QChm(const QString& fileName);
    ~QChm();
    bool open();
    void close();
    const QStringList& enumerateDirList(QString prefix);
    const QStringList& enumerateFileList();
    const QByteArray&  getEntityContent(const QString& url);
    const ChmEntityInfo& getEntityInfo(const QString& url);
    void setParam(int param,int value);
    void getTopicsByHandler(QHHCHandler& handler);
    bool unzip(QString dirName);
    const QString& getHHCFileName(){return _hhcFileName;}
    const QString& getHHKFileName(){return _hhkFileName;}
    void dontcallme(QString fileName){
        emit valueChanged(processdCount++);
        emit processedFileName(fileName);
    }
signals:
    void processedFileName(QString);
    void valueChanged(int);
private:
    int processdCount;
    bool isOpen();
    QString _fileName;
    QString _hhcFileName;
    QString _hhkFileName;
    void*  _chmFile;
    QStringList fileList;
    QStringList dirList;
    QMap<QString, QString> mapContent;
    QString Rbuffer;
    ChmEntityInfo unitInfo;
    QByteArray  content;
};

#endif // QCHM_H
